package com.xoomworks.rsfr.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * The persistent class for the companies database table.
 * Company getters & setters.
 * @author andrea.ghisa
 *
 */
public class Company extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private String companyName;

    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS", timezone="GMT")
    private Date createdOn;

    private byte[] logo;

    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS", timezone="GMT")
    private Date modifiedOn;

    // uni-directional many-to-one association to User
    private User createdBy;

    // uni-directional many-to-one association to User
    private User modifiedBy;

    /**Constructor with the specified parameters.
     * @param companyName Sting Represents the name of the company.
     * @param createdOn Date Represents the date when the company was created.
     * @param createdBy User Represents the user who created the company.
     */
    public Company(final String companyName, final Date createdOn, final User createdBy) {
        super();
        this.companyName = companyName;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
    }

    /**
     * Constructor with no fields.
     */
    public Company() {
    }

    /**
     * Gets the current company name.
     * @return companyName String Represents the company name.
     */
    public String getCompanyName() {
        return this.companyName;
    }

    /**
     * Sets the company name.
     * @param companyName String which is used to set the company name.
     */
    public void setCompanyName(final String companyName) {
        this.companyName = companyName;
    }

    /**
     * Gets the current date.
     * @return createdOn Date Represents the current date when company was created.
     */
    public Date getCreatedOn() {
        return this.createdOn;
    }

    /**
     * Sets the current date.
     * @param createdOn Date which is used to set the createdOn date.
     */
    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

    /**
     * Gets the logo of company.
     * @return logo Byte Array which represents the logo.
     */
    public byte[] getLogo() {
        return this.logo;
    }

    /**
     * Sets the logo of company.
     * @param logo Byte Array Which is used to set the logo.
     */
    public void setLogo(final byte[] logo) {
        this.logo = logo;
    }

    /**
     * Gets the date when the company was modified.
     * @return modifiedOn Date Represents the date when the company was modified.
     */
    public Date getModifiedOn() {
        return this.modifiedOn;
    }

    /**
     * Sets the date when the company was modified.
     * @param modifiedOn Date which is used to set the modifiedOn.
     */
    public void setModifiedOn(final Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    /**
     * Gets the user who created the company.
     * @return createdBy User Represents the user who created the company.
     */
    public User getCreatedBy() {
        return this.createdBy;
    }

    /**
     * Sets the user which created the company.
     * @param createdBy User which is used to set the createdBy.
     */
    public void setCreatedBy(final User createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * Gets the user who modified the company.
     * @return modifiedBy User Represents the user who modified the company.
     */
    public User getModifiedBy() {
        return this.modifiedBy;
    }

    /**
     * Sets the user who modified the company.
     * @param modifiedBy User which is used to set the modifiedBy.
     */
    public void setModifiedBy(final User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime * result)
                + ((companyName == null) ? 0 : companyName.hashCode());
        result = (prime * result) + Arrays.hashCode(logo);
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Company other = (Company) obj;
        if (companyName == null) {
            if (other.companyName != null) {
                return false;
            }
        } else if (!companyName.equals(other.companyName)) {
            return false;
        }
        if (!Arrays.equals(logo, other.logo)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Company [companyName=" + companyName + ", createdOn=" + createdOn + ", logo="
                + Arrays.toString(logo) + ", modifiedOn=" + modifiedOn + ", createdBy=" + createdBy
                + ", modifiedBy=" + modifiedBy + "]";
    }

}
